package controller

import (
	"dc-news-admin-api/common/global/consts"
	"dc-news-admin-api/common/resp"
	"dc-news-admin-api/service"
	"dc-news-admin-api/vo"
	"github.com/gin-gonic/gin"
	"github.com/spf13/cast"
	"net/http"
)

func GetUserListHandler(c *gin.Context) {
	service.GetUserListService(c)
}

func DeleteUserHandler(c *gin.Context) {
	idStr, ok := c.Params.Get("id")
	id := cast.ToInt(idStr)
	if !ok || id == 0 {
		c.JSON(http.StatusOK, resp.NewErrResp(consts.ParameterErrorCode, "参数错误"))
		return
	}
	service.DeleteUserService(c, id)
}

func SetUserMuteStatusHandler(c *gin.Context) {
	idStr, ok := c.Params.Get("id")
	id := cast.ToInt(idStr)
	if !ok || id == 0 {
		c.JSON(http.StatusOK, resp.NewErrResp(consts.ParameterErrorCode, "参数错误"))
		return
	}
	req := &vo.SetUserMuteStatusReq{}
	err := c.Bind(req)
	if err != nil {
		c.JSON(http.StatusOK, resp.NewErrResp(consts.ParameterErrorCode, "参数错误"))
		return
	}
	service.SetUserMuteStatusService(c, id, req)
}
